/*
 * Board.java
 *
 * Created on 19 sierpień 2008, 13:18
 */
package ania2.draughtsboard;

import ania2.BoardPosition;
import ania2.enums.Fields;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.util.EnumSet;
import javax.swing.JPanel;
import javax.swing.border.Border;

/**
 *
 * @author  pawel
 */
public class Board extends JPanel {

    //private int[] position = new int[32];
    private BoardPosition position;
    private Color whiteFieldColour;
    private Color blackFieldColour;
    private int borderWidth;
    private boolean boardDescriptionPrinted;
    private boolean rotated;
    private BoardRenderer renderer;
    private EnumSet<Fields> fieldsWithHighlightedFrame;
    private int fieldFrameWidth;
    private Color fieldFrameColour;
    public static final String PROP_BORDERWIDTH = "borderWidth";

    /** Creates new form BeanForm */
    public Board() {
        initComponents();
        whiteFieldColour = Color.WHITE;
        blackFieldColour = new Color(207, 182, 163);
        borderWidth = 16;
        fieldFrameWidth =4;
        fieldFrameColour = Color.ORANGE;
        boardDescriptionPrinted = true;
        position = new BoardPosition();
    }

    /**
     * Get the value of borderWidth
     *
     * @return the value of borderWidth
     */
    public int getBorderWidth() {
        return borderWidth;
    }

    /**
     * Set the value of borderWidth
     *
     * @param borderWidth new value of borderWidth
     */
    public void setBorderWidth(int borderWidth) {
        int oldBorderWidth = this.borderWidth;
        this.borderWidth = borderWidth;
        propertyChangeSupport.firePropertyChange(PROP_BORDERWIDTH, oldBorderWidth, borderWidth);
    }

    @Override
    public void setSize(int width, int height) {
        Dimension oldDimension = this.getSize();
        super.setSize(width, height);
        Dimension newDimension = new Dimension(width, height);
        propertyChangeSupport.firePropertyChange("size", oldDimension, newDimension);
    }

    /**
     * Get the value of rotated
     *
     * @return the value of rotated
     */
    public boolean isRotated() {
        return rotated;
    }

    /**
     * Set the value of rotated
     *
     * @param rotated new value of rotated
     */
    public void setRotated(boolean rotated) {
        this.rotated = rotated;
    }

    /**
     * Get the value of blackFieldColour
     *
     * @return the value of blackFieldColour
     */
    public Color getBlackFieldColour() {
        return blackFieldColour;
    }

    /**
     * Set the value of blackFieldColour
     *
     * @param blackFieldColour new value of blackFieldColour
     */
    public void setBlackFieldColour(Color blackFieldColour) {
        this.blackFieldColour = blackFieldColour;
    }

    /**
     * Get the value of whiteFieldColour
     *
     * @return the value of whiteFieldColour
     */
    public Color getWhiteFieldColour() {
        return whiteFieldColour;
    }

    /**
     * Set the value of whiteFieldColour
     *
     * @param whiteFieldColour new value of whiteFieldColour
     */
    public void setWhiteFieldColour(Color whiteFieldColour) {
        this.whiteFieldColour = whiteFieldColour;
    }

    @Override
    public Border getBorder() {
        return super.getBorder();
    }

    private PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(this);

    /**
     * Add PropertyChangeListener.
     *
     * @param listener
     */
    public void addPropertyChangeListener(PropertyChangeListener listener) {
        propertyChangeSupport.addPropertyChangeListener(listener);
    }

    /**
     * Remove PropertyChangeListener.
     *
     * @param listener
     */
    public void removePropertyChangeListener(PropertyChangeListener listener) {
        propertyChangeSupport.removePropertyChangeListener(listener);
    }

    /**
     * Get the value of renderer
     *
     * @return the value of renderer
     */
    public BoardRenderer getRenderer() {
        return renderer;
    }

    /**
     * Set the value of renderer
     *
     * @param renderer new value of renderer
     */
    public void setRenderer(BoardRenderer renderer) {
        this.renderer = renderer;
        this.repaint();
    }

    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        if (renderer == null) {
            renderer = new DefaultBoardRenderer(this);
        }
        renderer.paintBoard(g, this);
    }

    @Override
    public void setBorder(Border border) {
        return;
    }

    /**
     * Get the value of boardDescriptionPrinted
     *
     * @return the value of boardDescriptionPrinted
     */
    public boolean isBoardDescriptionPrinted() {
        return boardDescriptionPrinted;
    }

    /**
     * Set the value of boardDescriptionPrinted
     *
     * @param boardDescriptionPrinted new value of boardDescriptionPrinted
     */
    public void setBoardDescriptionPrinted(boolean boardDescriptionPrinted) {
        this.boardDescriptionPrinted = boardDescriptionPrinted;
    }

    public void setFieldFrameWidth(int fieldFrameWidth) {
        this.fieldFrameWidth = fieldFrameWidth;
    }

    public int getFieldFrameWidth() {
        return fieldFrameWidth;
    }

    public void setFieldsWithHighlightedFrame(EnumSet<Fields> fieldsWithHighlightedFrame) {
        this.fieldsWithHighlightedFrame = fieldsWithHighlightedFrame;
    }

    public EnumSet<Fields> getFieldsWithHighlightedFrame() {
        return fieldsWithHighlightedFrame;
    }

    public void setFieldFrameColour(Color fieldFrameColour) {
        this.fieldFrameColour = fieldFrameColour;
    }

    public Color getFieldFrameColour() {
        return fieldFrameColour;
    }

    public BoardPosition getPosition() {
        return position;
    }

    public void setPosition(BoardPosition position) {
        this.position = position;
    }
    
    
    
    

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(ania2.Ania2App.class).getContext().getResourceMap(Board.class);
        setToolTipText(resourceMap.getString("Form.toolTipText")); // NOI18N
        setName("Form"); // NOI18N
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    // End of variables declaration//GEN-END:variables
}
